package com.leyuan.printer;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import com.google.gson.JsonObject;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {





        String jsonStr = "{\n" +
                "    \"data\": []\n" +
                "}"; //json字符串




        JSONObject  JsonObject  =   new JSONObject(jsonStr);

      String value  =  JsonObject.getString("data");
        Log.i("TAG","JSONOBJECT");

        Object json = new JSONTokener(JsonObject.getString("data")).nextValue();
        if(json instanceof JSONObject){
           // JSONObject jsonObject = (JSONObject)json;
            Log.i("TAG","JSONOBJECT");

        }else if (json instanceof JSONArray){
           // JSONArray jsonArray = (JSONArray)json;
            Log.i("TAG","JSONArray");
        }


    }
}
